#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <netdb.h>

void error_handling(char* buf){
	fputs(buf, stderr);
	fputs('\n', stderr);
	exit(1);
}


int main(int argc, char *argv[])
{
	int i;
	struct hostent *host;
	if (argc!=2)
	{
		printf("usage error");
		exit(1);
	}

	host =gethostbyname(argv[1]);
	if (!host)
	{
		error_handling("get host error");
	}

	printf("offical name: %s \n", host->h_name);
	for (i =0;host->h_aliases[i] ;i++ )
	{
		printf("Aliases %d :%s \n", i+1, host->h_aliases[i]);
	}
	for (i=0;host->h_addr_list[i] ;i++ )
	{
		printf("IP addr %d : %s \n",i+1,
			inet_ntoa(*(struct in_addr*)host->h_addr_list[i]));
	}
	return 0;
}